require('./PagePdfView.less');


import moment from 'moment';
import Reflux from 'reflux';

import ReactMixin from 'react-mixin';
import Actions from './Actions'
import Store from './Store';
import { Link, Control,Route } from 'react-keeper';
import ChufaInfo from '../../../components/chufa/ChufaInfo';
import { Button,Page, Panel,PanelHeader, PanelBody, PanelFooter,ButtonArea, MediaBox,Cells,
  Cell,CellHeader,MediaBoxTitle,MediaBoxHeader,MediaBoxDescription,MediaBoxBody,MediaBoxInfo,Article,
  MediaBoxInfoMeta,Input,CellsTips,Icon,Label,CellsTitle,Toptips,Toast,InfiniteLoader,Popup,PopupHeader,Grids,
  Tab,Footer,FooterLinks,FooterLink,FooterText,
  TabBody,ActionSheet,
  NavBar,Flex,FlexItem,
  NavBarItem,
  CellBody,CellFooter, Form,FormCell,Radio,Gallery,GalleryDelete,Uploader,TextArea,SearchBar,PreviewItem} from  'react-weui/build/packages'
import rizhiup from './../../../assets/icon/上传.png';
import rizhiok from './../../../assets/icon/打钩.png';
import inputtp from './../../../assets/icon/输入.png';
import rqtp from './../../../assets/icon/日期.png';



const CellMore = () => (
  <Button type="primary" plain>Button</Button>
)

class PdfView extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showToast: false,
      showLoading: false,
      toastTimer: null,
      loadingTimer: null,
      urlDisplay:false,

    }
    this.showLoading = this.showLoading.bind(this);
    this.keywordChange = this.keywordChange.bind(this);
    this.handleChange = this.handleChange.bind(this);

    this.goselectjl = this.goselectjl.bind(this);
    this.setSelectObj = this.setSelectObj.bind(this);


    this.jlrqChange = this.jlrqChange.bind(this);
    this.jlrqClear = this.jlrqClear.bind(this);
    this.goInfo = this.goInfo.bind(this);
    this.goPage = this.goPage.bind(this);
    this.setSelectInfo = this.setSelectInfo.bind(this);

  }

  handleChange(e){
    console.log('htmlaaa');
  }

  goPage(){
    this.showLoading();
    console.log('html翻页001');
    Actions.addPage();
    console.log('html翻页001_over');
  }


  jlrqChange(e){

  }

  jlrqClear(e) {
  }


  keywordChange(text,e){
    console.log('html关键字');
    let keywords = [text];
    Actions.keySearch(keywords);
  }

  goInfo(){
     this.showLoading();
    Actions.goInfo();
  }

  showLoading() {
    this.setState({showLoading: true});

    this.state.loadingTimer = setTimeout(()=> {
      this.setState({showLoading: false});
    }, 2000);
  }

  setSelectInfo(obj) {
    console.log('返回obj');
    console.info(obj);

  }


  goselectjl(obj) {
    Control.go('/myyewu/rizhiaq',obj);
  }

  setSelectObj(obj) {
    console.log('返回');
    console.info(obj);
    Actions.setCurrentObj(obj);
  }





  render() {
    let pdfurl ="http://192.168.0.96:8080/hbjd/generic/web/viewer.html?file";
    return (
      <div className="page pdfview">
        <div>1</div>
        <page>

          <iframe src={this.state.pdfstore.pdfurl}
                  width="100%" height="800"
                  frameborder="0"/>


            <Toast icon="loading" show={this.state.showLoading}>加载中...</Toast>

        </page>
      </div>
    );
  }


  notice() {
    console.log('notice');
  }

  componentDidMount() {


  }

  componentDidMount() {
    Actions.initMode();
    if(Control.state){
      console.log('componentDidMount');
      Actions.loadMode(Control.state);
    }
  }

  shouldComponentUpdate(nextProps = {}, nextState = {}) {
    const thisProps = this.props || {},
      thisState = this.state.pdfstore || {};

    if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
      return true;
    }

    for (const key in nextProps) {
      if (thisProps[key] !== nextProps[key] ) {
        console.log(thisProps[key], nextProps[key]);
        return true;
      }
    }

    for (const key in nextState) {
      if (thisState[key] !== nextState[key] ) {
        return true;
      }
    }
    return false;
  }
}

PdfView.propTypes = {
  pmode: React.PropTypes.object.isRequired,
  peng: React.PropTypes.object.isRequired,
  imgls: React.PropTypes.object.isRequired,
  router: React.PropTypes.object.isRequired,
  location: React.PropTypes.object.isRequired,
}

ReactMixin.onClass(PdfView, Reflux.connect(Store, 'pdfstore'));


export default PdfView ;
